# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 简单使用 LCEL 连接组件.py
# @Author: dongguangwen
# @Date  : 2025-03-23 16:21
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

system_template = "Translate the following into {language}:"
prompt_template = ChatPromptTemplate.from_messages(
    [("system", system_template), ("user", "{text}")]
)

model = ChatOpenAI(model="Pro-128K",
                   api_key="dzCDkUHufCZEsuWlfVQd:",
                   base_url="https://spark-api-open.xf-yun.com/v1")

parser = StrOutputParser()

messages = [
    SystemMessage(content="Translate the following from English into Italian"),
    HumanMessage(content="hi!")
]

chain = prompt_template | model | parser
ret = chain.invoke({"language": "italian", "text": "hi"})
print(ret)

"""
Ciao
"""